﻿using System.Collections.Generic;
using System.Linq;
using Fabrication.ValueProviders;

namespace Fabrication
{
    public static class Fabricator
    {
        private static readonly FabricationScope fabricationScope = new FabricationScope();

        public static IBuilderOptions<T> Setup<T>()
        {
            fabricationScope.ClearOptionsFor<T>();
            return fabricationScope.Setup<T>();
        }

        public static T Generate<T>()
        {
            return Generate<T>(1).Single();
        }

        public static IEnumerable<T> Generate<T>(int numberOfItems)
        {
            return fabricationScope.Generate<T>(numberOfItems);
        }

        public static IEnumerable<T> Generate<T>(int minimumNumberOfItems, int maximumNumberOfItems)
        {
            return fabricationScope.Generate<T>(minimumNumberOfItems, maximumNumberOfItems);
        }

        public static void SetConvention<TParam, TProvider>()
            where TProvider : IValueProvider
        {
            fabricationScope.SetConvention<TParam, TProvider>();
        }

        public static void SetConvention<TPropertyType, TProvider>(string propertyName)
            where TProvider : IValueProvider
        {
            fabricationScope.SetConvention<TPropertyType, TProvider>(propertyName);
        }

        public static void SetConvention<TPropertyType>(IValueProvider provider, string propertyName)
        {
            fabricationScope.SetConvention<TPropertyType>(provider, propertyName);
        }

        public static void RemoveConvention(string propertyName)
        {
            fabricationScope.RemoveConvention(propertyName);
        }

        public static void RemoveConvention<TPropertyType>(string propertyName)
        {
            fabricationScope.RemoveConvention<TPropertyType>(propertyName);
        }

        public static void RemoveAllNamedConventions()
        {
            fabricationScope.RemoveAllNamedConventions();
        }
    }
}
